<?php
/**
 * User: long
 * Date: 2019/1/29
 * Time: 16:28
 */

require "./apps/libraries/Ftp.php";

echo 1;
// exit;

$result['code'] = -1;
$result['msg'] = '';
$result['data'] = '';

$config['host'] = '111.32.132.218';
$config['user'] = 'douniu';
$config['pass'] = 'io5aep9Zi6Ah';
$ftp = new Ftp($config);
$conn = $ftp->connect();
if (!$conn) {
    $result['msg'] = $ftp->get_error_msg();
} else {
    $result['msg'] = '链接成功';
    print_r($result);
    echo "\n";
}

$rootPath = "/data0/dk/cdn/host";
$host = 'https://s-js.sports.cctv.com/host';
$localFilePath = str_replace($host, $rootPath, $fileUrl); // 源文件
// $localFilePath = "/data0/dk/cdn/host/video/2019/01/29/15487340193564.mp4";
$localFilePath = "/data0/dk/cdn/host/transCodeV1/15450414016427.mp4";

$file_name = basename($localFilePath); // 弹出文件名
$remoteFile = date('Y/m/d/').$file_name; // 目标文件
$remoteFile = "temp/".$file_name; // 目标文件

echo $localFilePath."\n";
echo $remoteFile."\n";

//上传文件
if ($ftp->upload($localFilePath, $remoteFile)) {
    $result['code'] = 1;
    $result['msg'] = '上传FTP成功';
    $result['data'] = '';
    $result['fileFtpPath'] = '/'.$remoteFile;
} else {
    $result['code'] = -1;
    $result['msg'] = '上传FTP失败:' . $ftp->get_error_msg();
    $result['data'] = $fileUrl;
}

$ftp->close();
print_r($result);

